package model.dao;

import java.sql.Connection;
import java.sql.ResultSet;

import model.Account;
import model.DataAccess;
import model.User;

public class UserDAO {
	private DataAccess dao;
	public UserDAO(){
		dao = new DataAccess();
	}
	
	public User getUser(String username){
		try {
			Connection con = dao.getConnection();
			String sql ="select * from user where username='"+username+"';";
			ResultSet result = con.createStatement().executeQuery(sql);
			User user = null;
			if(result.next()){
				user = new User();
				Account acc = new Account();
				acc.setUsername(username);
				user.setAccount(acc);
				user.setEmail(result.getString("mail"));
				user.setName(result.getString("name"));
				user.setId(result.getInt("id"));
				user.setPhone(result.getString("phone"));
			}
			return user;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
}
